<template>
  <div class="water-quality-container">
    <!-- 查询区域 -->
    <div class="search-area">
      <el-form :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item label="行政区划:">
          <el-select clearable size="small" v-model="searchForm.region" placeholder="请选择行政区划">
            <el-option v-for="item in regionList" :key="item.code" :label="item.name" :value="item.code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年份:">
          <el-date-picker size="small"  value-format="yyyy" v-model="searchForm.mgryear" type="year" placeholder="选择年">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="水源地级别:">
          <el-select clearable size="small" v-model="searchForm.sydlevel" placeholder="选择水源地级别" style="width: 150px;">
            <el-option v-for="dict in dict.type.syd_level" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
            <!-- 这里可以根据实际数据添加选项 -->
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" @click="handleSearch">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button size="small" @click="handleReset">重置</el-button>
        </el-form-item>
        <!-- <el-form-item>
          <el-button @click="handleExport">
            <i class="el-icon-download" />
            导出
          </el-button>
        </el-form-item> -->
      </el-form>
    </div>

    <!-- 表格区域 -->
    <div class="table-area">
      <el-table :data="waterQualityData" style="width: 100%" border>
        <!-- 序号列 -->
        <el-table-column type="index" label="序号" width="60" align="center" />

        <!-- 水源地名称 -->
        <el-table-column prop="drinkSourceName" label="水源地名称" min-width="120" align="center" />

        <!-- 城市(城镇) -->
        <el-table-column prop="county" label="城市(城镇)" min-width="100" align="center" />

        <!-- 保护区建设完成率 -->
        <el-table-column label="保护区建设完成率 (%)" align="center">
          <el-table-column prop="isDivide" label="保护区划分" width="100" align="center" />
          <el-table-column prop="isSettingFlag" label="保护区标志设置" width="120" align="center" />
          <el-table-column prop="alreadyPartition" label="一级保护区隔离" width="120" align="center" />
        </el-table-column>

        <!-- 监测监控完成率 -->
        <el-table-column prop="dbWM" label="监测监控完成率 (%)" width="120" align="center" />

        <!-- 保护区整治率 -->
        <el-table-column label="保护区整治率 (%)" align="center">
          <el-table-column prop="pcr1" label="一级保护区" width="100" align="center" />
          <el-table-column prop="pcr2" label="二级保护区" width="100" align="center" />
          <el-table-column prop="pcqr" label="准保护区" width="100" align="center" />
        </el-table-column>

        <!-- 风险管控指标完成率 -->
        <el-table-column prop="rmrs" label="风险管控指标完成率 (%)" width="120" align="center" />

        <!-- 应急管理指标完成率 -->
        <el-table-column prop="onemes" label="应急管理指标完成率 (%)" width="120" align="center" />

        <!-- 管理制度完成率 -->
        <el-table-column prop="msrs" label="管理制度完成率 (%)" width="120" align="center" />
      </el-table>
      
      <!-- 分页区域 -->
      <div class="pagination-area">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { summaryEnvironmentalDrinkSource } from './api.js'
import { getRegionList } from '@/api/dataResources/monitorData/region.js'
export default {
  name: 'WaterQuality',
  dicts: ["syd_level"],
  data() {
    return {
      regionList: [],
      // 查询表单
      searchForm: {
        region: '',
        mgryear: '2025',
        sydlevel: ''
      },
      // 水质数据
      waterQualityData: [],
      // 分页相关
      pageNum: 1,
      pageSize: 10,
      total: 0
    }
  },
  created() {
    this.query()
  },
  methods: {
    async query() {
      await this.getRegionList()
      this.handleSearch()
    },
    async getRegionList() {
      let res = await getRegionList();
      if (res.code == 200) {
        this.regionList = res.rows;
      }
    },
    // 处理查询
    handleSearch() {
      // 实际应用中这里应该调用API获取数据
      console.log('查询条件:', this.searchForm)
      summaryEnvironmentalDrinkSource({
        ...this.searchForm,
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }).then(res => {
        this.waterQualityData = res.data || []
        this.total = res.total || 0
      })
      // 这里可以添加实际的查询逻辑
    },
    
    // 分页大小变化
    handleSizeChange(val) {
      this.pageSize = val
      this.pageNum = 1
      this.handleSearch()
    },
    
    // 当前页码变化
    handleCurrentChange(val) {
      this.pageNum = val
      this.handleSearch()
    },

    // 处理重置
    handleReset() {
      this.searchForm = {
        region: '',
        year: '2025',
        level: ''
      }
    },

    // 处理导出
    handleExport() {
      // 实际应用中这里应该调用导出API
      this.$message.success('数据导出成功')
    }
  }
}
</script>

<style scoped>
.water-quality-container {
  padding: 20px;
}

.search-area {
  margin-bottom: 20px;
}

.table-area {
  background: #fff;
  padding: 10px;
  border-radius: 4px;
}

.pagination-area {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>